﻿App.Deliver = function() {

    return {

        currentFormValues: {},

        getTopStore: function() {
            var store = new Ext.data.Store({
                autoLoad:true,
				baseParams : {start:0, limit:25},
				proxy: new Ext.data.HttpProxy({
					url : 'inhouse/items_o'
				}),
                remoteSort: false,
				reader: new Ext.data.JsonReader({
					totalProperty : 'totalCount',
					root : 'rows',
					idProperty : 'object_id',
					fields: [{
						name: 'object_id',
						type: 'string'
					},
					{
						name: 'objid',
						type: 'string'
					},{
						name: 'obj_name',
						type: 'string'
					},{
						name: 'obj_num',
						type: 'string'
					},
					{
						name: 'from_addr',
						allowBlank: false
					},
					{
						name: 'to_addr',
						allowBlank: false
					},
					{
						name: 'from_name',
						allowBlank: false
					},
					{
						name: 'to_name',
						allowBlank: false
					},
					{
						name:'from_tell'
					},
					{
						name:'cost_type'
					},
					{
						name: "to_tell"
					},
					{
						name:"send_type"
					},
					{
						name: "op_time",
						type: 'date',
						dateFormat: 'time'
					}]
				})
            });
            return store;
        },
        highLight: function(value) {
        	var key = App.Deliver.store.baseParams.query;
        	var v = value ? value.toString() : '';
        	if (Ext.isString(v) & Ext.isString(key)) {
        		if (key.length > 0) {
        			var re = new RegExp(key, "g");
        			return v.replace(re, "<span style='color:red;background-color:yellow;'>" + key + "</span>");
        		} else {
        			return v;
        		}
        	} else {
        		return v;
        	}
        },
        dateformate: function(value) {
        	return value.format("Y-m-d h:i:s");
        },
        createGrid: function(id) {

            var panel = Ext.getCmp(id);

            panel.body.dom.innerHTML = "";
            this.gird = this.getTopGrid();
       //     this.lowerGrid=this.getLowerGird();
            panel.add(this.gird);
      //      panel.add(this.lowerGrid);
            
        },
        
        getTopGrid: function (){
        	
        	var sm = new Ext.grid.CheckboxSelectionModel();
            var topGrid = new Ext.grid.GridPanel({
            //	anchor:'-0 50%',
            	width:"100%",
                loadMask: true,
            //    ref:"lowerGird",
                autoHeight:true,
                plugins: [Ext.ux.plugins.Print],//打印按钮
                viewConfig : {autoFill:false,forceFit:true},
                tbar: new Ext.PagingToolbar({ 
                	pageSize: 25 ,//分页必须加的参数.最好和store里面的limit保持一致
                	displayInfo: true,
                    store: this.store,
                    items:[
	               '-', new Ext.ux.form.SearchField({
                    store: this.store,
                    width: 110
                })]}),
                store: this.store,
                sm: sm,
                columns: [new Ext.grid.RowNumberer(), {
                    header: "货号",
                    width: 100,
                    sortable: true,
                    dataIndex: 'objid',
                    renderer: this.highLight
                },{
                    header: "货名",
                    width: 150,
                    sortable: true,
                    dataIndex: 'obj_name',
                    renderer: this.highLight
                },{
                    header: "件数",
                    width: 150,
                    sortable: true,
                    dataIndex: 'obj_num',
                    renderer: this.highLight
                },
                {
                    header: "发货地",
                    width: 150,
                    sortable: true,
                    dataIndex: 'from_addr',
                    renderer: this.highLight
                },
                {
                    header: "收货地",
                    width: 150,
                    sortable: true,
                    dataIndex: 'to_addr',
                    renderer: this.highLight
                },
            /*   {
                    header: "发货人",
                    width: 60,
                    sortable: true,
                    dataIndex: 'from_name',
                    renderer: this.highLight
                },
               */ {
                    header: "收货人",
                    width: 60,
                    sortable: true,
                    dataIndex: 'to_name',
                    renderer: this.highLight
                },
            /*    {
                    header: "发货人电话",
                    width: 100,
                    sortable: true,
                    dataIndex: 'from_tell'
                },
              */  {
                    header: "收货人电话",
                    width: 100,
                    sortable: true,
                    dataIndex: 'to_tell'
                },{
                    header: "发货方式",
                    width: 100,
                    sortable: true,
                    dataIndex: 'send_type'
                },
                {
                	header: "付款方式",
                    width: 150,
                    sortable: true,
                    dataIndex: 'cost_type'
                },
                {
                    header: "入库时间",
                    width: 150,
                    sortable: true,
                    dataIndex: 'op_time',
                    renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
                }]
            });
            return topGrid;
        },
        render: function(id) {
            if (!this.store) {
                this.store = this.getTopStore();
            }; //if(!this.store)
  //          if (!this.form) {
   //             this.form = this.getForm();
   //         }; //if(!this.form)
//
 //           if (!this.dlg) {
//                this.dlg = this.getDialog();
 //           }; //if(!this.dlg)
            this.createGrid(id);
        }

    }; //return
} ();
